/** 
 * Copyright 2010 Erlacher Felix, Estgfaeller Wolfgang, Ferula Patrick
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package at.socialconference.web.client;

import java.util.List;
import java.util.TreeMap;

import at.socialconference.inter.model.Conference;
import at.socialconference.inter.model.Login;
import at.socialconference.inter.model.Place;
import at.socialconference.inter.model.Talk;
import at.socialconference.inter.model.Updatetable;
import at.socialconference.inter.model.User;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

/**
 * Defines the methods provided by the GWT webservice
 */
@RemoteServiceRelativePath("SCwebService")
public interface SCwebService extends RemoteService {
	/**
	 * Login
	 * 
	 * @param user
	 *            Username of the client
	 * @param pwd
	 *            Password of the client
	 */
	public Integer login(String user, String pwd);

	/**
	 * Logout
	 */
	public void logout();

	/**
	 * Registers a user in the database
	 * 
	 * @param user
	 * @param login
	 * @gwt.typeArgs user <at.socialconference.inter.model.User>
	 * @gwt.typeArgs login <at.socialconference.inter.model.Login>
	 */
	public Integer register(User user, Login login);

	/**
	 * @gwt.typeArgs <at.socialconference.inter.model.User>
	 */
	public User getClientUser();

	/**
	 * Get a list of countries
	 */
	public TreeMap<Integer, String> getCountries();

	/**
	 * Fetches information of the given person from the official DBLP site.
	 * 
	 * @param firstName
	 * @param lastName
	 * @return A list of DBLP links mapped to a specific name.
	 */
	public TreeMap<String, String> getDBLPLinks(String firstName, String lastName);

	/**
	 * 
	 * @return
	 */
	public String getAuthURL();

	public Integer createAccToken(String pin, boolean store);

	public Integer follow(int id);
	
	public Integer unFollow(int id);
	
	//TODO rename -> something like TwitterFriends
	public String getFriends();

	public String getTimelines();

	/**
	 * @gwt.typeArgs 
	 *               <java.util.List<at.socialconference.inter.model.Conference>>
	 */
	public List<Conference> getConferences();

	/**
	 * @gwt.typeArgs <java.util.List<at.socialconference.inter.model.User>>
	 */
	public List<User> searchUser(String firstname, String lastname, int countryCode);

	/**
	 * Checks for a currently open and valid session
	 * @return
	 */
	public Boolean existsValidSession();
	
	/**
	 * Request friendship with somebody
	 * @param id Id of your friend
	 * @return
	 */
	public Integer friendRequest(int id);
	
	/**
	 * Fetch the list of current friend requests from other users
	 * @return
	 */
	public List<User> getFriendRequests();
	
	/**
	 * Accept a friendship request of somebody
	 * @param id Id of the person which requested friendship
	 * @return
	 */
	public Integer acceptFriendRequest(int id);
	
	/**
	 * Reject a friendship request of somebody
	 * @param id Id of the person which requested friendship
	 * @return
	 */
	public Integer rejectFriendRequest(int id);
	
	/**
	 * Updates an object in the database
	 * @param object
	 * @return
	 */
	public Integer updateObject(Updatetable object);
	
	/**
	 * Deletes an object in the database
	 * @param object
	 * @return
	 */
	public Integer deleteObject(Updatetable object);
	
	/**
	 * Insert an object in the database
	 * @param object
	 * @return
	 */
	public Integer insertObject(Updatetable object);
	
	public List<Place> getPlaces();
	
	public List<Talk> getTalks();
	
	public Boolean isEnrolled(Integer id);
	
	public Integer enroll(Integer id);
	/**
	 * Utility class for simplifying access to the instance of async service.
	 */
	public static class Util {
		private static SCwebServiceAsync instance;

		public static SCwebServiceAsync getInstance() {
			if (instance == null) {
				instance = (SCwebServiceAsync) GWT.create(SCwebService.class);

				ServiceDefTarget endpoint = (ServiceDefTarget) instance;
				endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "/SCwebService");
			}
			return instance;
		}
	}

}
